package com.efast.cafe.portal.service.common.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.bean.common.PortalCommonLaudBean;
import com.efast.cafe.portal.dao.common.PortalCommonLaudDao;
import com.efast.cafe.portal.entity.common.PortalCommonLaud;
import com.efast.cafe.portal.service.common.IPortalCommonLaudService;
@Service
@Transactional
public class PortalCommonLaudServiceImpl implements IPortalCommonLaudService{
	
	private PortalCommonLaudDao portalCommonLaudDao;
	
	@Autowired
	public void setPortalCommonLaudDao(PortalCommonLaudDao portalCommonLaudDao) {
		this.portalCommonLaudDao = portalCommonLaudDao;
	}

	@Override
	public void addLaud(PortalCommonLaud laud) {
		String companyCode = SpringWebUtils.getRequestCompany();
		String username = SpringWebUtils.getRequestUser();
		Integer count = portalCommonLaudDao.queryCurrentUserLaud(laud.getObjectId(), laud.getObjectType(), companyCode, username);
		laud.setCompanyCode(companyCode);
		laud.setCreateUser(username);
		if(count==0)
			portalCommonLaudDao.addLaud(laud);
	}

	@Override
	public void delLaud(Integer objectId, String objectType) {
		portalCommonLaudDao.deleteMyLaud(objectId, objectType, SpringWebUtils.getRequestCompany(), SpringWebUtils.getRequestUser());
	}

	@Override
	public PortalCommonLaudBean queryLaud(Integer objectId, String objectType) {
		PortalCommonLaudBean c = new PortalCommonLaudBean();
		String companyCode = SpringWebUtils.getRequestCompany();
		String username = SpringWebUtils.getRequestUser();
		c.setCount(portalCommonLaudDao.queryLaud(objectId, objectType, SpringWebUtils.getRequestCompany()));
		c.setCurrentUserLaud(portalCommonLaudDao.queryCurrentUserLaud(objectId, objectType, companyCode, username));
		return c;
	}

}
